package com.jcx.ldzj.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jcx.ldzj.entity.LoginSystemInfo;
import com.jcx.ldzj.service.ILoginSystemInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Ð¡Ìì
 * @since 2021-01-22
 */
@RestController
@Slf4j
@AllArgsConstructor
@RequestMapping("/login-system-info")
@Api(value = "系统登录信息", tags = "系统登录信息")
public class LoginSystemInfoController extends ApiController {
        @Autowired
        private ILoginSystemInfoService iLoginSystemInfoService;
       /**
       * 列表
       * @param pageNum
       * @param pageSize
       * @param loginSystemInfo
       * @return
       */
       @GetMapping("/list")
       @RequiresPermissions("basic:loginsystem:page")
       @ApiOperation(value = "列表", notes = "传入LoginSystemInfo对象")
       public R<IPage<LoginSystemInfo>> list(Integer pageNum, Integer pageSize,LoginSystemInfo loginSystemInfo) {
            QueryWrapper<LoginSystemInfo> queryWrapper=new QueryWrapper<>(loginSystemInfo);
           queryWrapper.orderByDesc("update_time_");
           if(loginSystemInfo.getUserName()!=null){
               queryWrapper.like("user_name_",loginSystemInfo.getUserName());
               loginSystemInfo.setUserName(null);
           }
           if(loginSystemInfo.getDepId()!=null){
               queryWrapper.like("dep_id_",loginSystemInfo.getDepId());
               loginSystemInfo.setDepId(null);
           }
            IPage<LoginSystemInfo> page = iLoginSystemInfoService.page(new Page<>(pageNum, pageSize), queryWrapper);
            return R.ok(page);
       }
       /**
       * 登录信息详情查询
       * @param id
       * @return
       */
       @GetMapping("/{id}")
       @ApiOperation(value = "详情", notes = "传入id")
       @RequiresPermissions("basic:loginsystem:view")
       public R<LoginSystemInfo> view(@PathVariable("id") String id) {
          LoginSystemInfo user = iLoginSystemInfoService.getById(id);
          return R.ok(user);
        }
        /**
         * 登录信息统计
         * @return
         */
        @GetMapping("/getloginCount")
        @ApiOperation(value = "登录信息统计")
        public R<List<Map<String, String>>> getloginCount() {
            List<Map<String, String>> getlogin = iLoginSystemInfoService.getloginCount();
            return R.ok(getlogin);
        }
 }
